# This file is part of Sonedyan.
#
# Sonedyan is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation;
# either version 3 of the License, or (at your option) any
# later version.
#
# Sonedyan is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2009-2012 Jimmy Dubuisson <jimmy.dubuisson@gmail.com>

# load the subset of 1grams
words <- read.table("core-words.txt")

# load matrix of core normalized time series (subset of 1grams)
mat <- read.table("normalized-core-words.csv", header = FALSE)

# set mat row names
rownames(mat) <- words$V1

# draw col means time series
s1 <- colMeans(mat)

# get "principal" time series (less correlated)
#s2 <- as.numeric(mat["principal",])
s2 <- as.numeric(mat["chemistry",])

# get "calculus" time series (most correlated)
#s3 <- as.numeric(mat["calculus",])
s3 <- as.numeric(mat["reaction",])

series1 <- ts(s1, start = 1800, end = 2000, frequency = 1)
series2 <- ts(s2, start = 1800, end = 2000, frequency = 1)
series3 <- ts(s3, start = 1800, end = 2000, frequency = 1)

pdf(file = "time-series.pdf")

#legend("topright", legend = c("Core Mean", "Calculus", "Principal"), lty = c(1:3))

ts.plot(series1, series2, series3, xlab = "Year", ylab = "Core Words Usage", main = "Core Usage Time Series", lty = c(1:3))
